class NestedInteger(object):
    def __init__(self, value=None):
        if value!=None: self.value = value
        else: self.value = []
    def add(self, elem):
        self.value.append(elem)
    def getList(self):
        return self.value

class Solution(object):
    def deserialize(self, s):
        tokens = []
        syntax = set(['[', ']', ','])
        acc = ''
        for c in s:
            if c in syntax:
                if len(acc)!=0:
                    tokens.append(int(acc))
                    acc = ''
                if c!= ',' :tokens.append(c)
            else:
                acc += c
        if len(acc)!=0:
            tokens.append(int(acc))
            acc = ''

        ind = 0

        def parse():
            nonlocal ind
            ret = NestedInteger()
            while ind<len(tokens):
                c = tokens[ind]
                ind+=1
                if isinstance(c, int):
                    ret.add(NestedInteger(c))
                elif c=='[':
                    ret.add(parse())
                elif c==']':
                    break
            return ret
        
        ret = parse().getList()[0]
        return ret

print(Solution().deserialize('324'))